package com.zara.store.common;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;

public class OfadJmsClient {

	public static void main(String[] args) {
		new OfadJmsClient().sendOfad(IntegrationTransformer.SAMPLE_OFAD2);
	}
	
	public void sendOfad(String xml) {
		try {
			InitialContext ctx = new InitialContext();
			
			QueueConnectionFactory qfactory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
			Queue queue = (Queue) ctx.lookup("queue/ofad");
			
			QueueConnection qCon = qfactory.createQueueConnection();
			QueueSession qSession = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
			QueueSender qSender = qSession.createSender(queue);
			
			TextMessage message = qSession.createTextMessage();
			message.setText(xml);
			qSender.send(message);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
